import  knex from 'knex';
import configDefault  from './config.default.js';
import { Datasource_dto } from "../models/datasource.dto.js";
var datasources=configDefault?.datasources as unknown as {default:Datasource_dto};


export   function initdb_1(){
    const myDBConfig = {
        debug: true,
        useNullAsDefault:true,
        client: "better-sqlite3",
        connection: {
          filename: "myEncryptedSQLiteDbFile.db"
        },
        pool: {

        }
      };
        var k=knex(myDBConfig);

    return  k;
}


export   function init_systemdb (){
  const myDBConfig = {
    debug: true,
    client: "mysql2",
    connection: {
      host :datasources?.default?.host|| '192.168.11.204',
      port :datasources?.default?.port|| 13306,
      user : datasources?.default?.user||'root',
      password : datasources?.default?.password||'15s6f9E3613f9k',
      database : datasources?.default?.database||'szq_system'
    },
    pool: {

    }
  };
  var a=(knex(myDBConfig))
  return a ;
}


export   function getdb (options:Datasource_dto){
  const myDBConfig = {
    debug: true,
    client: "mysql2",
    connection: {
      host : options.host||'192.168.11.204',
      port : options.port||13306,
      user : options.user||'root',
      password : options.password||'15s6f9E3613f9k',
      database : options.database||'szq_system'
    },
    pool: {

    }
  };
  var a=(knex(myDBConfig))

  return  a;
}

export function getsqlit_db(options:{filepathandfilename}){
  const myDBConfig = {
    debug: true,
    useNullAsDefault:true,
    client: "better-sqlite3",
    connection: {
      filename: options?.filepathandfilename
    },
    pool: {

    }
  };
  var a=(knex(myDBConfig))

  return  a;
}
